import config from '../../config.default'
export const SAVE_BREADCRUMB = Symbol('RECEIVE_BREADCRUMB');

//保存菜单
export const SAVE_SIDEMENUDATA = 'SAVE_SIDEMENUDATA';

//保存登陆信息
export const SAVE_LOGIN_INFO = 'SAVE_LOGIN';

//保存权限
export const SAVE_PERMISSIONS = 'SAVE_PERMISSIONS';

//初始化state
export const INIT_STATE = 'SAVE_NEWS_SOURCE_TAGS';

//刷新token
export const FETCH_REFRESH_TOKEN = Symbol('FETCH_REFRESH_TOKEN');

//保存最后时间
export const SAVE_LAST_FETCHED_TIME = Symbol('SAVE_LAST_FETCHED_TIME');

//默认更新
export const UPDATA_STATE = 'UPDATA_STATE';

//保存七牛token
export const GET_QINIUTOKEN = Symbol('GET_QINIUTOKEN');
//保存item
export const SAVE_CURRENT_ITEM_INFO = Symbol('SAVE_CURRENT_ITEM_INFO');
//保存租户信息
export const SAVE_TENANT_INFO = Symbol('SAVE_TENANT_INFO');
//刷一下租户token
export const FETCH_TENANT_TOKEN = Symbol('FETCH_TENANT_TOKEN');
export const initState: initStateType = {
  sideMenu: [],
  breadcrumb: [],
  permissions: [],
  qiniuToken: {},
  infoProjectStatus: 0,//列表状态
  loginInfo: false,
  tenantInfo: false,
  title: config.layout.defaultTitle,
  lastFetchedTime: 0,
  projectInfo: {

  },//项目信息 进入项目详情
  openCity: []
}

const common = (state = initState, action: Action) => {
  switch (action.type) {
    case SAVE_BREADCRUMB:
      return {
        ...state,
        breadcrumb: action.data || []
      }
    case SAVE_TENANT_INFO:
      return {
        ...state,
        tenantInfo: action.data
      }
    case SAVE_SIDEMENUDATA:
      return {
        ...state,
        sideMenu: action.data
      }
    case UPDATA_STATE:
      return {
        ...state,
        ...action.data
      }
    case SAVE_LOGIN_INFO:
      console.log(action)
      return {
        ...state,
        loginInfo: JSON.parse(JSON.stringify(action.data))
      }
    case SAVE_PERMISSIONS:
      return {
        ...state,
        permissions: action.data
      }
    case INIT_STATE:
      return {
        ...initState
      }
    case SAVE_LAST_FETCHED_TIME:
      return {
        ...state,
        lastFetchedTime: action.data
      }
    default:
      return state
  }
}

export default common
